import React, { useState } from 'react'
import { useEffect } from 'react';
import Offline from './components/offline';
import { fetchUserBuyGoodsDetail } from '@/server/shop';
import { getCurrentInstance, useReachBottom } from '@tarojs/taro'
import { loginData } from '@/utils/utils'
import Taro, { useShareAppMessage, useShareTimeline } from '@tarojs/taro'
import './index.scss'
const PayShopDetail = (props) => {
  const { params } = getCurrentInstance().router
  const { goodsId = '' } = params
  const { organizationId = '1', id } = loginData() || {}
  const [data, setData] = useState({})
  const { goodsBaseInfo = {} } = data
  const { goodsType = 'offline', goodsName } = goodsBaseInfo
  useEffect(() => {
    fetchData()
  }, [])
  useShareAppMessage(() => {
    let organizationId = Taro.getStorageSync("organizationId")
    return {
      title: goodsName,
      path: `pages/index/redirect/index?organizationId=${organizationId}&openType=wechatShare&type=shopDetail&goodsId=${goodsId}&shareUserId=${id}&shareUserType=user`, // 分享的路径
    };
  })
  useShareTimeline(() => {
    let organizationId = Taro.getStorageSync("organizationId")
    return {
      title: goodsName,
      path: `pages/index/redirect/index?organizationId=${organizationId}&openType=wechatShare&type=shopDetail&goodsId=${goodsId}&shareUserId=${id}&shareUserType=user`, // 分享的路径
    };
  })

  const renderObj = {
    offline: <Offline data={data}></Offline>,
    videoCourse: <Offline data={data}></Offline>,
    directLive: <Offline data={data}></Offline>,
    liveCourse: <Offline data={data}></Offline>,
    video: <Offline data={data}></Offline>,
    service: <Offline data={data}></Offline>,
  }[goodsType]
  const fetchData = () => {
    fetchUserBuyGoodsDetail({ organizationId, goodsId }).then(e => {
      setData(e)
    })
  }
  return (
    renderObj
  )
}
export default PayShopDetail